﻿create or replace function selectPosterminal(
	out refcursor, inout xml
	)
as
$$
	declare
		ref alias for $1;
		xmlQueryData alias for $2;
	begin
		open ref for
			select posterminal2xml(
                   poal.idposterminal, poal.serialnumber, 
                   poal.inventorynumber, 
                   posterminalmodel2xml(poel.idposterminalmodel, poel.nameposterminalmodel,
                     posterminalproducer2xml(poer.idposterminalproducer, poer.nameposterminalproducer)), 
                     null, null)
				from posterminal poal, posterminalmodel poel, posterminalproducer poer
                where
                  poal.idmodel = poel.idposterminalmodel
                  and poel.idposterminalproducer = poer.idposterminalproducer;
		return;
	end;
$$ language plpgsql	stable;